package com.example.day11;

import java.io.IOException;
import java.nio.CharBuffer;

public class DiffThreadRunnable {

    public static void main(String[] args) {
//        Thread t1=new T1();
//        Thread t2=new T1();

        Runnable r=new T2();
        Thread t1=new Thread(r);
        Thread t2=new Thread(r);
        t1.setName("窗口1：");
        t2.setName("窗口2：");

        t1.start();
        t2.start();
    }
}

class  T1 extends  Thread{
    private  int ticke=10;

    @Override
    public void run() {
        for (int i=10;i>=1;i--) {
            if (ticke > 0) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "正在卖票，剩余" + (--ticke));
            }
        }
    }
}

class  T2 implements Runnable {


    private  int ticke=10;
    @Override
    public void run() {

        for (int j=10;j>=1;j--) {
            if (ticke > 0) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "正在卖票，剩余" + (--ticke));
            }
        }
    }
}


